package com.xyzwps.server.paimon.ui.graphql

import com.xyzwps.server.paimon.app.ArticleAppService
import com.xyzwps.server.paimon.app.ContextUser
import com.xyzwps.server.paimon.app.dto.ArticlesGetInput
import com.xyzwps.server.paimon.app.dto.Me
import com.xyzwps.server.paimon.app.MeAppService
import com.xyzwps.server.paimon.app.HelloAppService
import com.xyzwps.server.paimon.common.CursorPage
import com.xyzwps.server.paimon.model.entity.Article
import com.xyzwps.server.paimon.spring.AuthUser
import com.xyzwps.server.paimon.ui.view.HelloView
import org.springframework.graphql.data.method.annotation.Argument
import org.springframework.graphql.data.method.annotation.QueryMapping
import org.springframework.stereotype.Controller

@Controller
class Queries(
    private val meAppService: MeAppService,
    private val helloAppService: HelloAppService,
    private val articleAppService: ArticleAppService
) {

    @QueryMapping
    fun article(@Argument uid: String): Article =
        articleAppService.get(uid)


    @QueryMapping
    fun articles(@Argument input: ArticlesGetInput, @AuthUser user: ContextUser): CursorPage<Article, String?> =
        articleAppService.get(user, input)


    @QueryMapping
    fun hello(): HelloView {
        return helloAppService.hello()
    }

    @QueryMapping
    fun me(@AuthUser user: ContextUser): Me {
        return meAppService.me(user)
    }
}
